package com.boarsoft.boar.soagov.app.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.soagov.app.AppSvcBiz;
import com.boarsoft.boar.soagov.entity.SvcInfo;
import com.boarsoft.boar.soagov.svc.SvcProtocolBiz;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.dao.PagedResult;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@RestController
@RequestMapping("/app/svc")
public class AppSvcAction {
	@Autowired
	private AppSvcBiz appSvcBiz;
	@Autowired
	private SvcProtocolBiz svcProtocolBiz;

	@RequestMapping("/add.do")
	@Authorized(code = "app.svc.add")
	public ReplyInfo<Object> add(String appId, String svcIds) {
		appSvcBiz.add(appId, svcIds.split(","));
		return ReplyInfo.SUCCESS;
	}

	@RequestMapping("/remove.do")
	@Authorized(code = "app.svc.remove")
	public ReplyInfo<Object> remove(String id, String key) {
		appSvcBiz.remove(id, key.split(","));
		// 删除服务和协议的关联
		svcProtocolBiz.delete(key.split(","));
		return ReplyInfo.SUCCESS;
	}

	@JsonIgnoreProperties({ "face" })
	@RequestMapping("/list.do")
	@Authorized(code = "app.svc.list")
	public ReplyInfo<Object> list(String appId, String key, String orderBy, int pageNo, int pageSize) {
		PagedResult<SvcInfo> pr = appSvcBiz.list(appId, key, orderBy, pageNo, pageSize);
		return new ReplyInfo<Object>(true, pr);
	}

}